package com.neuedu.utils;

import lombok.Data;
import org.apache.commons.text.WordUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 项目：mblog_java4
 * 创建时间：  2021-12-28   10:49
 * 作者 :jshand
 * 描述 :
 */
@Data
public class Table {

    private String tableName;
    private String entityName;
    private String daoName;
    private Integer columnCount;

    //主键列信息
    private String pkColumnName;
    private Column pkColumn;
    private Date now;

    //所有字段
    private StringBuilder columnNames = new StringBuilder() ;
    //除了主键外的其他列，为了插入、更新的时候 不操作主键
    private StringBuilder unPkcolumnNames = new StringBuilder() ;



    private List<Column> columnList = new ArrayList();


    public void appendColumnNames(String column) {
        if(columnNames.length() ==0){
            columnNames.append(column);
        }else{
            columnNames.append(", "+column);
        }
    }

    //追加非主键列
    public void appendUnPkcolumnNames(String column) {
        if(unPkcolumnNames.length() ==0){
            unPkcolumnNames.append(column);
        }else{
            unPkcolumnNames.append(", "+column);
        }
    }

    public String getEntityName() {
        String  name = WordUtils.capitalize(entityName,'_');
        name = name.replace("_","");
//        System.out.println(name);
        return name;
    }

    public void addcolumnList(Column column) {
        columnList.add(column);
    }

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public String getNow() {
        return sdf.format(new Date());
    }
}
